package cn.pconline.autoclub.entity;

import cn.pconline.autoclub.util.club.ComboCnd;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;

/**
 *
 * @author ppc 消息发送模块
 */
@Entity(tableName = "ac_message", secondLevelCache = false)
public class SendMsg {

    public static int SEND_BEIN = 1;
    public static int SEND_SETOUT = 2;
    public static int SEND_CENTER = 3;
    public static int SEND_END = 4;
    public static int SEND_BACK = 5;
    public static int STATUS_DELETE = -1;
    /**
     * 全部会员
     */
    public static int SCOPE_ALL_USER = 1;
    /**
     * 会长
     */
    public static int SCOPE_CHAIRMAN = 2;
    /**
     * 副会长以上（包含会长）
     */
    public static int SCOPE_VICE_CHAIRMAN = 3;
    /**
     * 认证车主
     */
    public static int SCOPE_CERTIFICATION_OWNER = 4;
    /**
     * 非认证车主
     */
    public static int SCOPE_NO_CERTIFICATION_OWNER = 5;
    /*
     * 发送者的车友会会员
     */
    public static int SCOPE_CLUB_MEMBER = 6;
    public static int TYPE_SYS = 0;
    public static int TYPE_CLUB_DYNA = 1;
    @Id
    @Column(name = "message_id")
    private long msgId;
    /**
     * 发送消息内容
     */
    @Column(name = "content")
    private String content;
    /**
     * 消息创建时间
     */
    @Column(name = "create_at")
    private Date createAt;
    /**
     * 消息创建者
     */
    @Column(name = "create_by")
    private long createBy;
    /**
     * 状态 1>发送，2》发送准备 3》发送中 4》发送完成 5》重发
     */
    @Column(name = "status")
    private int status;
    /**
     * 系统消息创建状态：2未创建 1创建中 0创建完
     */
    @Column(name = "create_status")
    private int createStatus;
    public static final int CREATE_STATUS_UNDO = 2;
    public static final int CREATE_STATUS_DOING = 1;
    public static final int CREATE_STATUS_DONE = 0;
    /**
     * 发送时间
     */
    @Column(name = "send_at")
    private Date sendAt;
    /**
     * 发送数量
     */
    @Column(name = "total_send")
    private int sendNum;
    /**
     * 发送范围，1-全部会员 2-会长 3-副会长 4-认证车主 5-非认证车主
     */
    @Column(name = "send_all")
    private int sendAll;
    /**
     * 更新时间
     */
    @Column(name = "update_at")
    private Date updateAt;
    /**
     * 修改者
     */
    @Column(name = "update_by")
    private long updateBy;
    /**
     * 剩余发送量
     */
    @Column(name = "less_num")
    private int lessNum;
    /**
     * 0系统稍息 1车友会动态消息 发送的消息类型
     */
    @Column(name = "type")
    private int type;
    /**
     * 省市品牌车系星级主题车友会的组合条件province:id:name,city:id:name,brand:id:name,series:id:name,clubLevel:id:name,theme:id:name,club:id:name;
     */
    @Column(name = "combo_cnd")
    private String comboCnd;

    public static List<ComboCnd> getComboCndList(String comboCnd) {
        List<ComboCnd> cndList = new ArrayList<ComboCnd>();
        String[] cndStr = comboCnd.split(";");
        for (String cnd : cndStr) {
            if (StringUtils.isNotBlank(cnd)) {
                String[] ids = cnd.split(",");
                long pid = 0, cid = 0, bid = 0, sid = 0, levelId = -1, themeId = 0, clubId = 0;
                String pname = "", cname = "", bname = "", sname = "",levelName = "", themeName = "", clubName = "";
                for (String id : ids) {
                    String[] ss = id.split(":");
                    if (ss.length != 3) {
                        continue;
                    }
                    if (id.startsWith("province:")) {
                        pid = Long.parseLong(ss[1]);
                        pname = ss[2];
                    }
                    if (id.startsWith("city:")) {
                        cid = Long.parseLong(ss[1]);
                        cname = ss[2];
                    }
                    if (id.startsWith("brand:")) {
                        bid = Long.parseLong(ss[1]);
                        bname = ss[2];
                    }
                    if (id.startsWith("series:")) {
                        sid = Long.parseLong(ss[1]);
                        sname = ss[2];
                    }
                    if(id.startsWith("clubLevel:")){
                    	levelId = Long.parseLong(ss[1]);
                    	levelName = ss[2];
                    }
                    if(id.startsWith("theme:")){
                    	themeId = Long.parseLong(ss[1]);
                    	themeName = ss[2];
                    }
                    if(id.startsWith("club:")){
                    	clubId = Long.parseLong(ss[1]);
                    	clubName = ss[2];
                    }
                }
                if (pid > 0 || cid > 0 || bid > 0 || sid > 0 || levelId >= 0 || themeId > 0 ||  clubId > 0) {
                    ComboCnd c = new ComboCnd();
                    c.setBrandId(bid);
                    c.setBrandName(bname);
                    c.setCityId(cid);
                    c.setCityName(cname);
                    c.setProvinceId(pid);
                    c.setProvinceName(pname);
                    c.setSeriesId(sid);
                    c.setSeriesName(sname);
                    c.setLevelId(levelId);
                    c.setLevelName(levelName);
                    c.setThemeId(themeId);
                    c.setThemeName(themeName);
                    c.setClubId(clubId);
                    c.setClubName(clubName);
                    cndList.add(c);
                }
            }
        }
        return cndList;

    }

    public List<ComboCnd> getComboCndList() {
        return getComboCndList(comboCnd);
    }

    public String getComboCnd() {
        return comboCnd;
    }

    public void setComboCnd(String comboCnd) {
        this.comboCnd = comboCnd;
    }

    public String getContent() {
        return content;
    }

    public int getStatus() {
        return status;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public long getCreateBy() {
        return createBy;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public Date getSendAt() {
        return sendAt;
    }

    public void setSendAt(Date sendAt) {
        this.sendAt = sendAt;
    }

    public long getMsgId() {
        return msgId;
    }

    public void setMsgId(long msgId) {
        this.msgId = msgId;
    }

    public int getSendNum() {
        return sendNum;
    }

    public void setSendNum(int sendNum) {
        this.sendNum = sendNum;
    }

    public int getSendAll() {
        return sendAll;
    }

    public void setSendAll(int sendAll) {
        this.sendAll = sendAll;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public int getLessNum() {
        return lessNum;
    }

    public void setLessNum(int lessNum) {
        this.lessNum = lessNum;
    }

    public long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(long updateBy) {
        this.updateBy = updateBy;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getCreateStatus() {
        return createStatus;
    }

    public void setCreateStatus(int createStatus) {
        this.createStatus = createStatus;
    }
    
}
